home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / includeEffectsGlobals.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  32.1 KB  |  1,353 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. global proc includeEffectsGlobals()
  18. {
  19.     //
  20.     // This proc does not do anything.  Its purpose
  21.     // is to force this script to be sourced only
  22.     // if it needs to be.  By having the following
  23.     // line at the top of the user's MEL script,
  24.     // then all of these procs become available
  25.     // to the script:
  26.     //
  27.     // includeEffectsGlobals();
  28.     //
  29. }
  30.  
  31. /////////////////////////////////////////////////////////////////////
  32. //
  33. // Array Procedures
  34. //
  35. /////////////////////////////////////////////////////////////////////
  36.  
  37. global proc string[] appendSingleToStringArray( string $base[], string $add )
  38. //
  39. // Description:
  40. //
  41. //    This proc appends a single item to an array.
  42. //
  43. {
  44.     $base[size($base)] = $add;
  45.     return $base;
  46. }
  47.  
  48. global proc float[] appendSingleToFloatArray( float $base[], float $add )
  49. //
  50. // Description:
  51. //
  52. //    This proc appends a single item to an array.
  53. //
  54. {
  55.     $base[size($base)] = $add;
  56.     return $base;
  57. }
  58.  
  59. global proc int[] appendSingleToIntArray( int $base[], int $add )
  60. //
  61. // Description:
  62. //
  63. //    This proc appends a single item to an array.
  64. //
  65. {
  66.     $base[size($base)] = $add;
  67.     return $base;
  68. }
  69.  
  70. global proc vector[] appendSingleToVectorArray( vector $base[], vector $add )
  71. //
  72. // Description:
  73. //
  74. //    This proc appends a single item to an array.
  75. //
  76. {
  77.     $base[size($base)] = $add;
  78.     return $base;
  79. }
  80.  
  81. global proc string[] appendArrayToStringArray( string $base[], string $add[] )
  82. //
  83. // Description:
  84. //
  85. //    This proc appends one array to another.
  86. //
  87. {
  88.     int $i;
  89.     for( $i = 0; $i < size($add); $i ++ )
  90.     {
  91.         $base[size($base)] = $add[$i];
  92.     }
  93.  
  94.     return $base;
  95. }
  96.  
  97. global proc float[] appendArrayToFloatArray( float $base[], float $add[] )
  98. //
  99. // Description:
  100. //
  101. //    This proc appends one array to another.
  102. //
  103. {
  104.     int $i;
  105.     for( $i = 0; $i < size($add); $i ++ )
  106.     {
  107.         $base[size($base)] = $add[$i];
  108.     }
  109.  
  110.     return $base;
  111. }
  112.  
  113. global proc vector[] appendArrayToVectorArray( vector $base[], vector $add[] )
  114. //
  115. // Description:
  116. //
  117. //    This proc appends one array to another.
  118. //
  119. {
  120.     int $i;
  121.     for( $i = 0; $i < size($add); $i ++ )
  122.     {
  123.         $base[size($base)] = $add[$i];
  124.     }
  125.  
  126.     return $base;
  127. }
  128.  
  129. global proc int[] appendArrayToIntArray( int $base[], int $add[] )
  130. //
  131. // Description:
  132. //
  133. //    This proc appends one array to another.
  134. //
  135. {
  136.     int $i;
  137.     for( $i = 0; $i < size($add); $i ++ )
  138.     {
  139.         $base[size($base)] = $add[$i];
  140.     }
  141.  
  142.     return $base;
  143. }
  144.  
  145. global proc int findInStringArray( string $value, string $array[] )
  146. {
  147.     int $i;
  148.     for( $i = 0; $i < size( $array ); $i ++ )
  149.     {
  150.         if( $array[$i] == $value )
  151.         {
  152.             return $i;
  153.         }
  154.     }
  155.  
  156.     return -1;
  157. }
  158.  
  159. global proc int indexInIntegerList( int $item, int $list[] )
  160. //
  161. // Searches for $item in $list and if found, returns its index.
  162. // If item not found, returns -1;
  163. {
  164.     int $result = -1;
  165.     int $j;
  166.  
  167.     for ( $j = size($list)-1; $j >= 0; $j-- )
  168.     {
  169.         if ( $item == $list[$j] )
  170.         {
  171.             $result = $j;
  172.             break;
  173.         }
  174.     }
  175.     return $result;
  176. }
  177.  
  178.  
  179. global proc int indexInList( string $item, string $list[] )
  180. //
  181. // Description:
  182. //   If $item appears in $list, returns its index. Otherwise returns -1.
  183. //
  184. {
  185.     int $result = -1;
  186.     int $count = size($list);
  187.     int $j;
  188.     for ( $j = 0; $j < $count; $j++ )
  189.     {
  190.         if ( $item == $list[ $j ] )
  191.         {
  192.             $result = $j;
  193.             break;
  194.         }
  195.     }
  196.     return $result;
  197. }
  198.  
  199.  
  200. global proc string getUnexcludedItem( string $list[], string $excludedList[] )
  201. //
  202. // Description:
  203. //  Return an item from $list which is NOT in $excludedList.
  204. // If there is no such item, return an empty string.
  205. // The routine does a linear search through the list of candidates and
  206. // will always return the first eligible item.
  207. {
  208.     string $result = "";
  209.     int $count = size($list);
  210.     int $i;
  211.     for ( $i = 0; $i < $count; $i++ )
  212.     {
  213.         if ( indexInList($list[$i], $excludedList) == -1 )
  214.         {
  215.             $result = $list[$i];
  216.             break;
  217.         }
  218.     }
  219.     return $result;
  220. }
  221.  
  222.  
  223.  
  224. global proc string getUnexcludedIntegerItem( int $list[], int $excludedList[] )
  225. //
  226. // Description:
  227. //  Return index of an item from $list which is NOT in $excludedList.
  228. // If there is no such item, return -1. Note that we return an index, not the item itself.
  229. // The routine does a linear search through the list of candidates and
  230. // will always return the first eligible item.
  231. {
  232.     int $result = -1;
  233.     int $count = size($list);
  234.     int $i;
  235.     for ( $i = 0; $i < $count; $i++ )
  236.     {
  237.         if ( indexInIntegerList($list[$i], $excludedList) == -1 )
  238.         {
  239.             $result = $i;
  240.             break;
  241.         }
  242.     }
  243.     return $result;
  244. }
  245.  
  246.  
  247. global proc string getMatchingItem( string $list[], string $matchList[] )
  248. //
  249. // Description:
  250. //  Return an item from $list which is also in $excludedList.
  251. // If there is no such item, return an empty string.
  252. // The routine does a linear search through the list of candidates and
  253. // will always return the first eligible item.
  254. // This routine is the inverse of getUnexcludedItem.
  255. {
  256.     string $result = "";
  257.     int $count = size($list);
  258.     int $i;
  259.     for ( $i = 0; $i < $count; $i++ )
  260.     {
  261.         if ( indexInList( $list[$i], $matchList ) >= 0 )
  262.         {
  263.             $result = $list[$i];
  264.             break;
  265.         }
  266.     }
  267.     return $result;
  268. }
  269.  
  270. global proc string[] intersectSets( string $set1[], string $set2[] )
  271. //
  272. // Returns a string array holding all the lements which are in both 
  273. // $set1 and $set2, i.e. the set intersection.
  274. {
  275.     string $result[];
  276.     clear( $result );
  277.  
  278.     int $i;
  279.     int $resultCount = 0;
  280.     int $count1 = size( $set1 );
  281.     for ($i = 0; $i < $count1; $i++)
  282.     {
  283.         // If this item is also in the other set, add it to the result
  284.         //
  285.         if (indexInList( $set1[$i], $set2 ) >= 0)
  286.         {
  287.             $result[ $resultCount++ ] = $set1[$i];
  288.         }
  289.  
  290.     }
  291.     return $result;
  292. }
  293.  
  294. /////////////////////////////////////////////////////////////////////
  295. //
  296. // DAG Procedures
  297. //
  298. /////////////////////////////////////////////////////////////////////
  299.  
  300.  
  301. global proc int objectIsEmpty( string $object )
  302. //
  303. // Description:
  304. //   returns 1 if face count of $object is 0, false otherwise
  305. {
  306.     int $result = 0;
  307.  
  308.     int $faceCount[] = `polyEvaluate -face $object`;
  309.     if ( $faceCount[0] == 0 )
  310.         $result = 1;
  311.  
  312.     return $result;
  313. }
  314.  
  315. global proc float boundingBoxVolume( string $object )
  316. //
  317. //  Determine the volume of the bounding box of the given object.
  318. //
  319. {
  320.     float $volume = 0.0;
  321.  
  322.     if ( objectExists( $object ) )
  323.     {
  324.         // Get the bounding box of the object.
  325.         //
  326.         $bbAttr = $object + ".boundingBoxMin";
  327.         $minBB  = `getAttr $bbAttr`;
  328.         $bbAttr = $object + ".boundingBoxMax";
  329.         $maxBB  = `getAttr $bbAttr`;
  330.  
  331.         // Determine the volume of the bounding box.
  332.         //
  333.         $volume = ($maxBB[0]-$minBB[0]) * ($maxBB[1]-$minBB[1]) * ($maxBB[2]-$minBB[2]);
  334.     }
  335.  
  336.     return $volume;
  337. }
  338.  
  339. global proc int objectExists( string $object )
  340. {
  341.     string $list[] = `ls $object`;
  342.  
  343.     if ( size($list) > 0 )
  344.     {
  345.         return true;
  346.     }
  347.  
  348.     return false;
  349. }
  350.  
  351.  
  352.  
  353. global proc string[] getShapesFromObjects( string $objects[], int $includeIntermediates )
  354. //
  355. // Description:
  356. //
  357. //    This procedure takes a list of objects, and returns all of the
  358. // shapes at or below those object in the DAG.  If the $includeIntermediate
  359. // argument is zero, then all intermediate objects will be skipped.
  360. //
  361. {
  362.     string $result[];
  363.     clear( $result );
  364.  
  365.     int $i;
  366.     for( $i = 0; $i < size( $objects ); $i ++ )
  367.     {
  368.         string $shapes[] = getShapesFromObject( $objects[$i], $includeIntermediates );
  369.         $result = appendArrayToStringArray( $result, $shapes );
  370.     }
  371.  
  372.     return $result;
  373. }
  374.  
  375. global proc string[] getShapesFromObject( string $object, int $includeIntermediates )
  376. //
  377. // Description:
  378. //
  379. //    This procedire will return all of the shapes at or below the
  380. // given object in the DAG.  If the $includeIntermediate argument is
  381. // zero, then all intermediate objects will be skipped.
  382. //
  383. {
  384.     string $result[];
  385.     clear( $result );
  386.  
  387.     string $dagObject[] = `ls -shapes $object`;
  388.     //
  389.     // If $object is already a shape then we can just return
  390.     // the list of shapes with the same name.
  391.     //
  392.     if( size($dagObject) > 0 )
  393.     {
  394.         $result = $dagObject;
  395.     }
  396.     else
  397.     //
  398.     // Otherwise, we find all of the transforms that match the
  399.     // name $object, and find all of the shapes beneath each
  400.     // of them.
  401.     //
  402.     {
  403.         string $transforms[] = `ls -type transform $object`;
  404.         int $i;
  405.         for( $i = 0; $i < size( $transforms ); $i ++ )
  406.         {
  407.             string $shapes[] = `ls -dag -shapes $transforms[$i]`;
  408.             //
  409.             // If we want intermediate objects as well, then we
  410.             // do not need to filter this list.  We can just append
  411.             // it to the current list of shapes.
  412.             //
  413.             if( $includeIntermediates == 1 )
  414.             {
  415.                 $result = appendArrayToStringArray( $result, $shapes );
  416.             }
  417.             else
  418.             //
  419.             // If we do not want intermediate objects, then we only
  420.             // append the anmes of shapes that are not intermediate.
  421.             //
  422.             {
  423.                 int $j;
  424.                 for( $j = 0; $j < size( $shapes ); $j ++ )
  425.                 {
  426.                     if( isObjectIntermediate( $shapes[$j] ) == 0 )
  427.                     {
  428.                         $result = appendSingleToStringArray( $result, $shapes[$j] );
  429.                     }
  430.                 }
  431.             }
  432.         }
  433.     }
  434.  
  435.     return $result;
  436. }
  437.  
  438. global proc string getShapeFromObject( string $object, int $whichShape, int $includeIntermediates )
  439. //
  440. // Description:
  441. //
  442. //    This procedure will get all of the shapes at and below
  443. // the given object in the dag.  Then it will return the shape
  444. // specified by the $whichShape argument.  If the
  445. // $includeIntermediates argument is zero, then all intermediate
  446. // shapes will be skipped.
  447. //
  448. {
  449.     string $result = "";
  450.     string $shapes[] = getShapesFromObject( $object, $includeIntermediates );
  451.  
  452.     if( $whichShape < size($shapes) )
  453.     {
  454.         $result = $shapes[$whichShape];
  455.     }
  456.  
  457.     return $result;
  458. }
  459.  
  460. global proc int isValidPolyObject( string $object )
  461. {
  462.     int $result = false;
  463.     if (size($object) > 0)
  464.     {
  465.         string $tmp[] = `ls $object`;
  466.         if (size($tmp[0]) > 0)
  467.         {
  468.             string $shapeName = getShapeFromObject( $object, 0, 0 );
  469.             if (size($shapeName) > 0)
  470.             {
  471.                 if (nodeType( $shapeName ) == "mesh")
  472.                     $result = true;
  473.             }
  474.         }
  475.     }
  476.     return $result;
  477. }
  478.  
  479. global proc int isObjectVisible( string $object )
  480. //
  481. // Description:
  482. //
  483. //    This procedure examines the given object's path in the DAG
  484. // and determines whether or not any part of the path is invisible.
  485. // If it finds an invisible parent, then this object is also not visible,
  486. // and it returnes 0.  If all of the parents are visible, and the object
  487. // itself is visible, then the procedure returns 1.  If more than one
  488. // object exists with the given name, then 1 is returned if ANY of them
  489. // are visible.
  490. //
  491. {
  492.     if( `objExists $object` == 0 )
  493.     {
  494.         return 0;
  495.     }
  496.  
  497.     int $result = 0;
  498.     string $fullPaths[] = `ls -long $object`;
  499.     int $pathCount = size( $fullPaths );
  500.     int $i;
  501.     for( $i = 0; $i < $pathCount; $i ++ )
  502.     {
  503.         string $parents[];
  504.         tokenize( $fullPaths[$i], "|", $parents );
  505.         int $thisPathVisible = 1;
  506.         int $j;
  507.         string $thisPath = "";
  508.         for( $j = 0; $j < size($parents); $j ++ )
  509.         {
  510.             $thisPath += ("|"+$parents[$j]);
  511.             string $testPath = $thisPath;
  512.             if( substring( $testPath, size($testPath)-1, size($testPath) ) == "->" )
  513.             {
  514.                 $testPath = substring( $testPath, 1,  size($testPath)-2 );
  515.             }
  516.             int $vis = `getAttr ($testPath+".visibility")`;
  517.             if( $vis == 0 )
  518.             {
  519.                 $thisPathVisible = 0;
  520.                 break;
  521.             }
  522.         }
  523.  
  524.         if( $thisPathVisible == 1 )
  525.         {
  526.             $result = 1;
  527.         }
  528.     }
  529.  
  530.     return $result;
  531. }
  532.  
  533. global proc int isObjectIntermediate( string $object )
  534. //
  535. // Description:
  536. //
  537. //    This procedure examines the given object's path in the DAG
  538. // and determines whether or not any part of the path is intermediate.
  539. // If it finds an intermediate parent, then this object is also intermediate,
  540. // and it returnes 1.  If none of the parents are intermediate, and the object
  541. // itself is not intermediate, then the procedure returns 0.  If more than one
  542. // object exists with the given name, then 1 is returned if ANY of them
  543. // are intermediate.
  544. //
  545. {
  546.     if( `objExists $object` == 0 )
  547.     {
  548.         return 0;
  549.     }
  550.  
  551.     int $result = 0;
  552.     string $fullPaths[] = `ls -long $object`;
  553.     int $pathCount = size( $fullPaths );
  554.     int $i;
  555.     for( $i = 0; $i < $pathCount; $i ++ )
  556.     {
  557.         string $parents[];
  558.         tokenize( $fullPaths[$i], "|", $parents );
  559.         int $thisPathIntermediate = 0;
  560.         int $j;
  561.         string $thisPath = "";
  562.         for( $j = 0; $j < size($parents); $j ++ )
  563.         {
  564.             $thisPath += ("|"+$parents[$j]);
  565.             string $testPath = $thisPath;
  566.             if( substring( $testPath, size($testPath)-1, size($testPath) ) == "->" )
  567.             {
  568.                 $testPath = substring( $testPath, 1,  size($testPath)-2 );
  569.             }
  570.             int $int = `getAttr ($testPath+".intermediateObject")`;
  571.             if( $int == 1 )
  572.             {
  573.                 $thisPathIntermediate = 1;
  574.                 break;
  575.             }
  576.         }
  577.  
  578.         if( $thisPathIntermediate == 1 )
  579.         {
  580.             $result = 1;
  581.         }
  582.     }
  583.  
  584.     return $result;
  585. }
  586.  
  587. global proc int isObjectTemplated( string $object )
  588. //
  589. // Description:
  590. //
  591. //    This procedure examines the given object's path in the DAG
  592. // and determines whether or not any part of the path is templated.
  593. // If it finds a templated parent, then this object is also templated,
  594. // and it returnes 1.  If none of the parents are templated, and the object
  595. // itself is not templated, then the procedure returns 0.  If more than one
  596. // object exists with the given name, then 1 is returned if ANY of them
  597. // are templated.
  598. //
  599. {
  600.     if( `objExists $object` == 0 )
  601.     {
  602.         return 0;
  603.     }
  604.  
  605.     int $result = 0;
  606.     string $fullPaths[] = `ls -long $object`;
  607.     int $pathCount = size( $fullPaths );
  608.     int $i;
  609.     for( $i = 0; $i < $pathCount; $i ++ )
  610.     {
  611.         string $parents[];
  612.         tokenize( $fullPaths[$i], "|", $parents );
  613.         int $thisPathTemplated = 0;
  614.         int $j;
  615.         string $thisPath = "";
  616.         for( $j = 0; $j < size($parents); $j ++ )
  617.         {
  618.             $thisPath += ("|"+$parents[$j]);
  619.             string $testPath = $thisPath;
  620.             if( substring( $testPath, size($testPath)-1, size($testPath) ) == "->" )
  621.             {
  622.                 $testPath = substring( $testPath, 1,  size($testPath)-2 );
  623.             }
  624.             int $temp = `getAttr ($testPath+".template")`;
  625.             if( $temp == 1 )
  626.             {
  627.                 $thisPathTemplated = 1;
  628.                 break;
  629.             }
  630.         }
  631.  
  632.         if( $thisPathTemplated == 1 )
  633.         {
  634.             $result = 1;
  635.         }
  636.     }
  637.  
  638.     return $result;
  639. }
  640.  
  641. global proc int isObjectInUnderWorld( string $object )
  642. //
  643. // Description:
  644. //
  645. //    This procedure checks to see if the given object is in the
  646. // underworld of some other object in the scene.  This is done
  647. // by looking for the underworld path symbol "->" in the full path
  648. // of the object.  For now, this is the only way that I know how
  649. // to check this.
  650. //
  651. {
  652.     if( `objExists $object` == 0 )
  653.     {
  654.         return 0;
  655.     }
  656.  
  657.     string $fullPaths[] = `ls -long $object`;
  658.     string $match = match( "->", $fullPaths[0] );
  659.     if( $match == "->" )
  660.     {
  661.         return 1;
  662.     }
  663.     else
  664.     {
  665.         return 0;
  666.     }
  667. }
  668.  
  669. /////////////////////////////////////////////////////////////////////
  670. //
  671. // Object Procedures
  672. //
  673. /////////////////////////////////////////////////////////////////////
  674.  
  675. global proc string createDecomposeMatrixNode()
  676. //
  677. // Description:
  678. //        This procedure will load a plugin, decomposeMatrix.so,
  679. //        and then create a node of the plugin. loadPlugin may be warning
  680. //        if it has already exist but won't cause problem.
  681. //
  682. {
  683.     string $node = "";
  684.  
  685.     // Load plugin decomposeMatrix.so, then create a plugin node.
  686.     //
  687.     if( `pluginInfo -query -loaded decomposeMatrix` == 0 )
  688.     {
  689.         if( catch(`loadPlugin -quiet "decomposeMatrix"`) )
  690.         {
  691.             error("Can't load plugin node decomposeMatrix.");
  692.             return $node;
  693.         }
  694.     }
  695.  
  696.     // create a node.
  697.     //
  698.     $node = `createNode decomposeMatrix`;
  699.  
  700.     return $node;
  701. }
  702.  
  703.  
  704. global proc string superDuplicateCurve( string $curve )
  705. //
  706. // Description:
  707. //
  708. //    This procedure duplicates the given curve in such a way that
  709. // ALL phsical modifications to the original curve are pass on to
  710. // the duplicate curve.  The only changes that are not passed on
  711. // are changes to the number of spans and the degree.  Therefore,
  712. // using the addToCurve tool will not also add new CV's to the
  713. // duplicated curve.
  714. //
  715. {
  716.     string $result = "";
  717.     if( `objExists $curve` == 0 )
  718.     {
  719.         error("The object \""+$curve+"\" does not exist.");
  720.         return $result;
  721.     }
  722.  
  723.     string $curveShape = getShapeFromObject( $curve, 0, 0 );
  724.     if( $curveShape == "" )
  725.     {
  726.         error("Can not find the shape for the object \""+$curve+"\".");
  727.         return $result;
  728.     }
  729.  
  730.     if( `objectType $curveShape` != "nurbsCurve" )
  731.     {
  732.         error("Can not find a curve shape from the object \""+$curve+"\".");
  733.         return "";
  734.     }
  735.  
  736.     //
  737.     // If the original object is in the underworld, then
  738.     // display an error message and return.  This effect
  739.     // will not work on underworld objects, because their
  740.     // topology changes as they move on the parent object.
  741.     // This effect can not handle changing topology, since
  742.     // direct connections are made.
  743.     //
  744.     if( isObjectInUnderWorld( $curveShape ) == 1 )
  745.     {
  746.         error( $curve + " is an underworld object.  This procedure does not work for underworld objects.");
  747.         return "";
  748.     }
  749.  
  750.     // create a plugin node: decomposeMatrix.
  751.     //
  752.     string $dMatrix = createDecomposeMatrixNode();
  753.     if( `objectType $dMatrix` != "decomposeMatrix" )
  754.     {
  755.         error("Can't create decomposeMatrix node.");
  756.         return "";
  757.     }
  758.  
  759.     //
  760.     // First, we duplicate the original curve, without
  761.     // keeping the construction history.  We rename
  762.     // this new curve so that it is identified.
  763.     //
  764.     string $dups[] = `duplicateCurve -ch 0 $curveShape`;
  765.     string $dup = $dups[0];
  766.     select $dup;
  767.     rename "superDuplicatedCurve1";
  768.     $dups = `ls -sl`;
  769.     $dup = $dups[0];
  770.  
  771.     string $dupShape = getShapeFromObject( $dup, 0, 0 );
  772.  
  773.     // Connect oringinal curve shape with duplicated one.
  774.     //
  775.     string $from = ($curveShape+".local");
  776.     string $to = ($dupShape+".create");
  777.     connectAttr -f $from $to;
  778.  
  779.     // Connect oringinal surface shape with decomposeMatrix node.
  780.     //
  781.     $from = ($curveShape+".worldMatrix[0]");
  782.     $to = ($dMatrix+".inputMatrix");
  783.     connectAttr -f $from $to;
  784.  
  785.     // Connect decomposeMatrix node with duplicated surface shape.
  786.     //
  787.     $from = ($dMatrix+".outputTranslate");
  788.     $to = ($dup+".translate");
  789.     connectAttr -f $from $to;
  790.  
  791.     $from = ($dMatrix+".outputRotate");
  792.     $to = ($dup+".rotate");
  793.     connectAttr -f $from $to;
  794.  
  795.     $from = ($dMatrix+".outputScale");
  796.     $to = ($dup+".scale");
  797.     connectAttr -f $from $to;
  798.  
  799.     $from = ($dMatrix+".outputShear");
  800.     $to = ($dup+".shear");
  801.     connectAttr -f $from $to;
  802.  
  803.     $result = $dup;
  804.     select $result;
  805.     return $result;
  806. }
  807.  
  808.  
  809. global proc string superDuplicateSurface( string $surface )
  810. //
  811. // Description:
  812. //
  813. //    This procedure duplicates the given surface in such a way that
  814. // all phsical modifications to the original one are pass on to
  815. // the duplicate one.  The only changes that are not passed on
  816. // are changes to the number of spans and the degree.
  817. //
  818. {
  819.     string $result = "";
  820.     if( `objExists $surface` == 0 )
  821.     {
  822.         error("The object \""+$surface+"\" does not exist.");
  823.         return $result;
  824.     }
  825.  
  826.     string $surfaceShape = getShapeFromObject( $surface, 0, 0 );
  827.     if( $surfaceShape == "" )
  828.     {
  829.         error("Can not find the shape for the object \""+$surface+"\".");
  830.         return $result;
  831.     }
  832.  
  833.     if( `objectType $surfaceShape` != "nurbsSurface" )
  834.     {
  835.         error("Can't find a surface shape from the object \""+$surface+"\".");
  836.         return $result;
  837.     }
  838.  
  839.     // create a plugin node: decomposeMatrix.
  840.     //
  841.     string $dMatrix = createDecomposeMatrixNode();
  842.     if( `objectType $dMatrix` != "decomposeMatrix" )
  843.     {
  844.         error("Can't create decomposeMatrix node.");
  845.         return "";
  846.     }
  847.  
  848.     // First, we duplicate original surface, without keeping the construction
  849.     // history. We rename this new nurbs surface so that it can be identified.
  850.     //
  851.     string $dups[] = `duplicate -name "superDuplicatedSurface" $surfaceShape`;
  852.     string $dup = $dups[0];
  853.     string $dupShape = getShapeFromObject( $dup, 0, 0 );
  854.  
  855.     // Connect oringinal surface shape with duplicated one.
  856.     //
  857.     string $from = ($surfaceShape+".local");
  858.     string $to = ($dupShape+".create");
  859.     connectAttr -f $from $to;
  860.  
  861.     // Connect oringinal surface shape with decomposeMatrix node.
  862.     //
  863.     $from = ($surfaceShape+".worldMatrix[0]");
  864.     $to = ($dMatrix+".inputMatrix");
  865.     connectAttr -f $from $to;
  866.  
  867.     // Connect decomposeMatrix node with duplicated surface shape.
  868.     //
  869.     $from = ($dMatrix+".outputTranslate");
  870.     $to = ($dup+".translate");
  871.     connectAttr -f $from $to;
  872.  
  873.     $from = ($dMatrix+".outputRotate");
  874.     $to = ($dup+".rotate");
  875.     connectAttr -f $from $to;
  876.  
  877.     $from = ($dMatrix+".outputScale");
  878.     $to = ($dup+".scale");
  879.     connectAttr -f $from $to;
  880.  
  881.     $from = ($dMatrix+".outputShear");
  882.     $to = ($dup+".shear");
  883.     connectAttr -f $from $to;
  884.  
  885.     $result = $dup;
  886.     select $result;
  887.     return $result;
  888. }
  889.  
  890. global proc string getUniqueAttrName( string $object, string $attrName )
  891. {
  892.     string $uniqueAttr = $attrName;
  893.  
  894.     if( `objExists $object` == 0 )
  895.     {
  896.         return "";
  897.     }
  898.  
  899.     if( $attrName == "" )
  900.     {
  901.         return "";
  902.     }
  903.  
  904.     string $pieces[];
  905.     clear $pieces;
  906.  
  907.     int $pieceCount = tokenize( $attrName, "#", $pieces);
  908.     if( $pieceCount == 0 )
  909.     {
  910.         return "";
  911.     }
  912.     else if( $pieceCount == 1 )
  913.     {
  914.         if( substring( $attrName, size($attrName), size($attrName ) ) != "#" ) 
  915.         {
  916.             if( `attributeQuery -node $object -exists $pieces[0]` == 0 )
  917.             {
  918.                 return $pieces[0];
  919.             }
  920.         }
  921.     }
  922.  
  923.     int $currentValue = 1;
  924.     int $done = 0;
  925.     while( $done == 0 )
  926.     {
  927.         string $testString = "";
  928.         int $i;
  929.         for( $i = 0; $i < $pieceCount; $i ++ )
  930.         {
  931.             $testString += $pieces[$i];
  932.             if( $i == 0 )
  933.             {
  934.                 $testString += $currentValue;
  935.             }
  936.         }
  937.  
  938.         if( `attributeQuery -node $object -exists $testString` == 0 )
  939.         {
  940.             $done = 1;
  941.             $uniqueAttr = $testString;
  942.         }
  943.  
  944.         $currentValue ++;
  945.     }
  946.  
  947.     return $uniqueAttr;
  948. }
  949.  
  950. global proc string addMarkingAttribute( string $object, string $attrName, int $multi )
  951. {
  952.     if( `objExists $object` == 0 )
  953.     {
  954.         error("The object, \""+$object+"\", does not exist to add an attribute to.");
  955.     }
  956.  
  957.     string $newName = getUniqueAttrName( $object, $attrName );
  958.     if( $multi == 0 )
  959.         addAttr -at message -ln $newName $object;
  960.     else
  961.         addAttr -at message -multi -indexMatters 0 -ln $newName $object;
  962.  
  963.     return $newName;
  964. }
  965.  
  966. global proc string markObjectWithAttribute( string $markedObject, string $markingObject, string $attribute )
  967. {
  968.     if( `objExists $markedObject` == 0 )
  969.     {
  970.         warning("Object, \""+$markedObject+"\", does not exist and can not be marked.");
  971.         return "";
  972.     }
  973.  
  974.     if( `objExists $markingObject` == 0 )
  975.     {
  976.         warning("Object, \""+$markingObject+"\", does not exist and can not be used to mark "+$markedObject+".");
  977.         return "";
  978.     }
  979.  
  980.     if( `attributeQuery -node $markingObject -exists $attribute` == 0 )
  981.     {
  982.         // warning("Attribute, \""+$attribute+"\", does not exist, adding it as non-multi to \""+$markingObject+"\".");
  983.         $attribute = addMarkingAttribute( $markingObject, $attribute, 0 );
  984.     }
  985.  
  986.     if( `attributeQuery -node $markingObject -multi $attribute` == 1 )
  987.     {
  988.         connectAttr -nextAvailable ($markedObject+".message") ($markingObject+"."+$attribute);
  989.     }
  990.     else
  991.     {
  992.         connectAttr -f ($markedObject+".message") ($markingObject+"."+$attribute);
  993.     }
  994.  
  995.     return $attribute;
  996. }
  997.  
  998. global proc string[] getMarkedObjects( string $object, string $attribute )
  999. {
  1000.     string $result[];
  1001.     clear( $result );
  1002.  
  1003.     if( `objExists $object` == 0 )
  1004.     {
  1005.         warning("Object, \""+$object+"\", does not exist.");
  1006.         return $result;
  1007.     }
  1008.  
  1009.     if( `attributeQuery -node $object -exists $attribute` == 0 )
  1010.     {
  1011.         warning("Object, \""+$object+"\", does not have the attribute, \""+$attribute+"\".");
  1012.         return $result;
  1013.     }
  1014.  
  1015.     $result = `listConnections -shapes true -source true -destination false ($object+"."+$attribute)`;
  1016.     return $result;
  1017. }
  1018.  
  1019. /////////////////////////////////////////////////////////////////////
  1020. //
  1021. // Selection Procedures
  1022. //
  1023. /////////////////////////////////////////////////////////////////////
  1024.  
  1025. global proc string[] getSelectedList( string $type )
  1026. //
  1027. // Description:
  1028. //
  1029. //    This procedure will return the objects from the
  1030. // selection list filtered by the string passed in.
  1031. // Currently, this procedure does not return any
  1032. // components selected.
  1033. //
  1034. {
  1035.     string $selection[];
  1036.     clear( $selection );
  1037.     if( $type == "all" )
  1038.     {
  1039.         $selection = `ls -objectsOnly -sl`;
  1040.     }
  1041.     else if( $type == "shapes" )
  1042.     {
  1043.         $selection = `ls -objectsOnly -shapes -sl`;
  1044.     }
  1045.     else if( $type == "transforms" )
  1046.     {
  1047.         $selection = `ls -objectsOnly -transforms -sl`;
  1048.     }
  1049.     else if( $type == "allShapes" )
  1050.     //
  1051.     // This option will return all of the shapes at or
  1052.     // under the selected objects in the DAG.
  1053.     //
  1054.     {
  1055.         $selection = `ls -objectsOnly -dag -shapes -sl`;
  1056.     }
  1057.     else if( $type == "geometry" )
  1058.     //
  1059.     // This option will return all of the geometry shapes
  1060.     // that are currently selected.
  1061.     //
  1062.     {
  1063.         $selection = `ls -objectsOnly -geometry -sl`;
  1064.     }
  1065.     else if( $type == "allGeometry" )
  1066.     //
  1067.     // This option will return all of the geometry shapes
  1068.     // at or under the selected objects in the DAG.
  1069.     //
  1070.     {
  1071.         $selection = `ls -objectsOnly -dag -allPaths -geometry -sl`;
  1072.     }
  1073.     else if( $type == "allPolys" )
  1074.     //
  1075.     // This option will return all of the polygonal shapes
  1076.     // at or under the selected objects in the DAG.
  1077.     //
  1078.     {
  1079.         $selection = `ls -objectsOnly -dag -allPaths -geometry -type mesh -sl`;
  1080.     }
  1081.     else if( $type == "allNurbs" )
  1082.     //
  1083.     // This option will return all of the nurbs surface shapes
  1084.     // at or under the selected objects in the DAG.
  1085.     //
  1086.     {
  1087.         $selection = `ls -objectsOnly -dag -allPaths -geometry -type nurbsSurface -sl`;
  1088.     }
  1089.     else if( $type == "allCurves" )
  1090.     //
  1091.     // This option will return all of the nurbs curves shapes
  1092.     // at or under the selected objects in the DAG.
  1093.     //
  1094.     {
  1095.         $selection = `ls -objectsOnly -dag -allPaths -geometry -type nurbsCurve -sl`;
  1096.     }
  1097.     else
  1098.     //
  1099.     // This option lets that calling procedure or script specify the
  1100.     // type of selected objects to return.
  1101.     //
  1102.     {
  1103.         $selection = `ls -type $type -sl`;
  1104.     }
  1105.  
  1106.     return $selection;
  1107. }
  1108.  
  1109. global proc string getSelectedObject( int $whichOne )
  1110. {
  1111.     string $sl[] = `ls -sl`;
  1112.     int $s = size( $sl );
  1113.     if( $whichOne >= $s )
  1114.     {
  1115.         return "";
  1116.     }
  1117.  
  1118.     return $sl[$whichOne];
  1119. }
  1120.  
  1121. /////////////////////////////////////////////////////////////////////
  1122. //
  1123. // String Procedures
  1124. //
  1125. /////////////////////////////////////////////////////////////////////
  1126.  
  1127. global proc string removeStartAndEndWhiteSpace( string $in )
  1128. //
  1129. // Description:
  1130. //
  1131. //    This proc removes any spaces, tabs, or newlines from the start and
  1132. // end of a string.  Then the resulting string is returned.
  1133. //
  1134. {
  1135.     if( size( $in ) == 0 )
  1136.         return $in;
  1137.  
  1138.     //
  1139.     // First remove all white space from the beginning of
  1140.     // the string.
  1141.     //
  1142.     while( ( substring( $in, 1, 1 ) == " " ) ||
  1143.             ( substring( $in, 1, 1 ) == "\t" ) ||
  1144.             ( substring( $in, 1, 1 ) == "\n" ) )
  1145.     {
  1146.         $in = substring( $in, 2, size($in) );
  1147.     }
  1148.  
  1149.     //
  1150.     // Now remove all white space from the end of the string.
  1151.     //
  1152.     while( ( substring( $in, size($in), size($in) ) == " " ) ||
  1153.             ( substring( $in, size($in), size($in) ) == "\t" ) ||
  1154.             ( substring( $in, size($in), size($in) ) == "\n" ) )
  1155.     {
  1156.         $in = substring( $in, 1, size($in) - 1 );
  1157.     }
  1158.  
  1159.     return $in;
  1160. }
  1161.  
  1162. global proc string removeAllWhiteSpace( string $in )
  1163. //
  1164. // Description:
  1165. //
  1166. //    This procedire removes all spaces, tabs, and newlines from
  1167. // the given string.  The result is returned.
  1168. //
  1169. {
  1170.     //
  1171.     // First we remove all of the spaces from the string.
  1172.     //
  1173.     string $last = $in;
  1174.     string $out = substitute( " ", $last, "" );
  1175.     while( $last != $out )
  1176.     {
  1177.         $last = $out;
  1178.         $out = substitute( " ", $last, "" );
  1179.     }
  1180.  
  1181.     //
  1182.     // Then we remove all of the tabs from the string.
  1183.     //
  1184.     $last = $out;
  1185.     $out = substitute( "\t", $last, "" );
  1186.     while( $last != $out )
  1187.     {
  1188.         $last = $out;
  1189.         $out = substitute( "\t", $last, "" );
  1190.     }
  1191.  
  1192.     //
  1193.     // Now we remove all of the newlines from the string.
  1194.     //
  1195.     $last = $out;
  1196.     $out = substitute( "\n", $last, "" );
  1197.     while( $last != $out )
  1198.     {
  1199.         $last = $out;
  1200.         $out = substitute( "\n", $last, "" );
  1201.     }
  1202.  
  1203.     return $out;
  1204. }
  1205.  
  1206. global proc lockTranslation( string $group )
  1207. {
  1208.     setAttr -lock 1 ($group+".translateX");
  1209.     setAttr -lock 1 ($group+".translateY");
  1210.     setAttr -lock 1 ($group+".translateZ");
  1211.     setAttr -keyable 0 ($group+".translateX");
  1212.     setAttr -keyable 0 ($group+".translateY");
  1213.     setAttr -keyable 0 ($group+".translateZ");
  1214. }
  1215.  
  1216. global proc unlockTranslation( string $group )
  1217. {
  1218.     setAttr -lock 0 ($group+".translateX");
  1219.     setAttr -lock 0 ($group+".translateY");
  1220.     setAttr -lock 0 ($group+".translateZ");
  1221.     setAttr -keyable 1 ($group+".translateX");
  1222.     setAttr -keyable 1 ($group+".translateY");
  1223.     setAttr -keyable 1 ($group+".translateZ");
  1224. }
  1225.  
  1226. global proc lockRotation( string $group )
  1227. {
  1228.     setAttr -lock 1 ($group+".rotateX");
  1229.     setAttr -lock 1 ($group+".rotateY");
  1230.     setAttr -lock 1 ($group+".rotateZ");
  1231.     setAttr -keyable 0 ($group+".rotateX");
  1232.     setAttr -keyable 0 ($group+".rotateY");
  1233.     setAttr -keyable 0 ($group+".rotateZ");
  1234. }
  1235.  
  1236. global proc unlockRotation( string $group )
  1237. {
  1238.     setAttr -lock 0 ($group+".rotateX");
  1239.     setAttr -lock 0 ($group+".rotateY");
  1240.     setAttr -lock 0 ($group+".rotateZ");
  1241.     setAttr -keyable 1 ($group+".rotateX");
  1242.     setAttr -keyable 1 ($group+".rotateY");
  1243.     setAttr -keyable 1 ($group+".rotateZ");
  1244. }
  1245.  
  1246. global proc lockScale( string $group )
  1247. {
  1248.     setAttr -lock 1 ($group+".scaleX");
  1249.     setAttr -lock 1 ($group+".scaleY");
  1250.     setAttr -lock 1 ($group+".scaleZ");
  1251.     setAttr -keyable 0 ($group+".scaleX");
  1252.     setAttr -keyable 0 ($group+".scaleY");
  1253.     setAttr -keyable 0 ($group+".scaleZ");
  1254. }
  1255.  
  1256. global proc unlockScale( string $group )
  1257. {
  1258.     setAttr -lock 0 ($group+".scaleX");
  1259.     setAttr -lock 0 ($group+".scaleY");
  1260.     setAttr -lock 0 ($group+".scaleZ");
  1261.     setAttr -keyable 1 ($group+".scaleX");
  1262.     setAttr -keyable 1 ($group+".scaleY");
  1263.     setAttr -keyable 1 ($group+".scaleZ");
  1264. }
  1265.  
  1266. global proc lockShear( string $group )
  1267. {
  1268.     setAttr -lock 1 ($group+".shearXY");
  1269.     setAttr -lock 1 ($group+".shearXZ");
  1270.     setAttr -lock 1 ($group+".shearYZ");
  1271.     setAttr -keyable 0 ($group+".shearXY");
  1272.     setAttr -keyable 0 ($group+".shearXZ");
  1273.     setAttr -keyable 0 ($group+".shearYZ");
  1274. }
  1275.  
  1276. global proc unlockShear( string $group )
  1277. {
  1278.     setAttr -lock 0 ($group+".shearXY");
  1279.     setAttr -lock 0 ($group+".shearXZ");
  1280.     setAttr -lock 0 ($group+".shearYZ");
  1281.     setAttr -keyable 1 ($group+".shearXY");
  1282.     setAttr -keyable 1 ($group+".shearXZ");
  1283.     setAttr -keyable 1 ($group+".shearYZ");
  1284. }
  1285.  
  1286. global proc lockTransformations( string $group )
  1287. {
  1288.     lockTranslation( $group );
  1289.     lockRotation( $group );
  1290.     lockScale( $group );
  1291.     lockShear( $group );
  1292. }
  1293.  
  1294. global proc unlockTransformations( string $group )
  1295. {
  1296.     unlockTranslation( $group );
  1297.     unlockRotation( $group );
  1298.     unlockScale( $group );
  1299.     unlockShear( $group );
  1300. }
  1301.  
  1302.  
  1303. /////////////////////////////////////////////////////////////////////
  1304. //
  1305. // Debugging Procedures
  1306. //
  1307. /////////////////////////////////////////////////////////////////////
  1308.  
  1309.  
  1310. global proc debugPrintIntegerArray( string $label, int $list[] )
  1311. {
  1312.     print( $label );
  1313.     int $j;
  1314.  
  1315.     for ( $j = 0; $j < size($list); $j++ )
  1316.     {
  1317.         print( $list[$j] + " " );
  1318.     }
  1319.     print("\n");
  1320. }
  1321.  
  1322. global proc debugPrintStringArray( string $label, string $list[] )
  1323. {
  1324.     print( $label );
  1325.     int $j;
  1326.  
  1327.     for ( $j = 0; $j < size($list); $j++ )
  1328.     {
  1329.         print( $list[$j] + " " );
  1330.     }
  1331.     print("\n");
  1332. }
  1333.  
  1334. global proc saveEffectStateToFile( string $fileName )
  1335. //
  1336. // Saves the current state of the effect to a binary file called $fileName.mb.
  1337. // Renames the current scene to this name.
  1338. {
  1339.     print("Saving scene to file " + $fileName + "\n");
  1340.     file -rename $fileName;
  1341.     file -f -save -type "mayaBinary";
  1342. }
  1343.  
  1344. global proc breakExecution( string $out )
  1345. //
  1346. // Breaks execution by introducing an intentional runtime error.
  1347. // First, outputs string $out.  This is like a breakpoint, exept you cannot continue from it.
  1348. {
  1349.     print("Breaking execution at " + $out + "\n");
  1350.     string $foo = `ls`;    
  1351. }
  1352.  
  1353.